package com.link.base.task;

import com.link.base.base.contract.service.ContractService;
import com.link.base.core.basic.config.xxljob.BaseLinkJobHandler;
import com.link.core.util.DateUtil;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.annotation.JobHandler;
import com.xxl.job.core.log.XxlJobLogger;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Date;

/**
 * 每月更新上月定点合同零件对应的零件历史价格信息
 * 
 * @author 王昊
 * @date 2020/11/25 09:52
 */
@JobHandler(value = "upsertPartHistoryJobHandler")
@Component
public class TaskUpsertPartHistory extends BaseLinkJobHandler {

    @Resource
    private ContractService contractService;

    @Override
    public ReturnT<String> execute(String params) throws Exception {
        try {
            // XxlJobLogger 打印的日志会体现在调度中心的执行日志中
            XxlJobLogger.log("XXL-JOB,零件历史价格更新开始...");
            XxlJobLogger.log("零件历史价格更新开始时间:[ " + DateUtil.dateToStr(new Date(), "yyyy-MM-dd HH:mm:ss") + " ]");
            // 调用父的方法设置登录信息
            super.setLogin(params);
            contractService.upsertPartHistory();
            XxlJobLogger.log("零件历史价格更新结束时间:[ " + DateUtil.dateToStr(new Date(), "yyyy-MM-dd HH:mm:ss") + " ]");
            return ReturnT.SUCCESS;
        } catch (Exception e) {
            XxlJobLogger.log(e.getMessage());
            return ReturnT.FAIL;
        }
    }

}
